<template>
  <div class="m-carousel">
    <div class="close" @click="close">×</div>
    <Carousel ref="mCarousel" :interval="5000" arrow="never" :height="height" :autoplay="false" indicator-position="outside" style="width: 730px;" @change="handleChange">
      <carousel-item v-for="(item, index) in imgs" :key="index"><img :src="item" alt="" style="width: 100%; height: 100%;object-fit: contain;" /></carousel-item>
    </Carousel>
    <div class="btn-left" @click="prev"><img src="~/assets/images/left-arrow1.png" alt="" /></div>
    <div class="btn-right" @click="next"><img src="~/assets/images/right-arrow1.png" alt="" /></div>
    <div class="shadow">{{ title || '相册图片' }}</div>
  </div>
</template>

<script>
import { Carousel, CarouselItem } from 'element-ui';

export default {
  name: 'MCarousel',
  components: { Carousel, CarouselItem },
  data() {
    return {
      activeIndex: 0
    };
  },
  props: {
    height: {
      type: String,
      default: '486px'
    },
    title: String,
    imgs: {
      type: Array,
      default() {
        return [];
      }
    }
  },
  created() {},
  methods: {
    handleChange(index) {
      this.activeIndex = index;
    },
    prev() {
      this.$refs.mCarousel.setActiveItem(this.activeIndex - 1);
    },
    next() {
      this.$refs.mCarousel.setActiveItem(this.activeIndex + 1);
    },
    close() {
      this.$emit('close', true);
    }
  }
};
</script>

<style lang="scss" scoped>
@import '~@/assets/style/common.scss';

.m-carousel {
  position: relative;

  /deep/ .el-carousel__arrow {
    width: 30px;
    height: 80px;
    background-color: $theme-color-1;
    border-radius: 0;

    &.el-carousel__arrow--left {
      left: 0;
    }

    &.el-carousel__arrow--right {
      right: 0;
    }
  }

  .btn-left,
  .btn-right {
    position: absolute;
    width: 30px;
    height: 80px;
    background-color: $theme-color-1;
    z-index: 9;
    top: calc(50% - 40px);
    color: #fff;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
  }

  .btn-left {
    left: -15px;
  }

  .btn-right {
    right: -15px;
  }

  .shadow {
    position: absolute;
    height: 60px;
    left: 0;
    right: 0;
    bottom: 27px;
    z-index: 9;
    background-color: #000;
    opacity: 0.6;
    font-size: 16px;
    text-align: center;
    line-height: 60px;
    color: #fff;
  }

  .close {
    width: 30px;
    height: 30px;
    border: solid 1px $theme-color-1;
    border-radius: 30px;
    //line-height: 30px;
    //text-align: center;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 20px;
    color: $theme-color-1;
    position: absolute;
    right: -30px;
    top: -30px;
    cursor: pointer;
  }
}
</style>
